package client;

import client.gin.AppGinjector;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.sencha.gxt.widget.core.client.box.AlertMessageBox;
import shared.rpc.ExampleAction;
import shared.rpc.ExampleResult;

/**
 * @author vinakov
 */
public class Main implements EntryPoint {
    public final AppGinjector injector = AppGinjector.INSTANCE;

    EventBus eventBus = injector.getEventBus();

    public void onModuleLoad() {

        RootPanel.get().add(new TextBox());
        RootPanel.get().add(new TextArea());
        Button button = new Button("click me");
        button.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                injector.getDispatcher().execute(new ExampleAction(),new AsyncCallback<ExampleResult>() {
                    public void onFailure(Throwable caught) {
                        new AlertMessageBox("Error","Error").show();
                    }

                    public void onSuccess(ExampleResult result) {
                        AlertMessageBox messageBox = new AlertMessageBox("Ответ от сервера",result.getStatus());
                        messageBox.show();
                    }
                });
            }
        });
        RootPanel.get().add(button);
    }

}
